#ifndef __NETCOMM_NETCLIENT_H__
#define __NETCOMM_NETCLIENT_H__

#include "netservice.h"
#include "netchatmsg.h"

#include <boost/asio.hpp>
#include <boost/bind.hpp>
#include <iostream>

class NetClient
{
public:
    typedef boost::asio::ip::tcp::socket TcpSocket;
    typedef boost::asio::ip::tcp::resolver::iterator endPointIteratorType;

    NetClient(endPointIteratorType endpoint_iterator);

    void write(const NetChatMsg& a_msg);
    void close();

private:

    void handle_connect(const boost::system::error_code &);
    void handle_read_header(const boost::system::error_code &);
    void handle_read_body(const boost::system::error_code &);
    void do_write(NetChatMsg);
    void handle_write(const boost::system::error_code &);
    void do_close();

private:
    TcpSocket          m_socket;
    NetChatMsg         m_read_msg;
    chat_message_queue m_write_msgs;
};

#endif //__NETCOMM_NETCLIENT_H__
